//
//  @ Project : Galaxy Star Trading System
//  @ File Name : TradeUser.cpp
//  @ Date : 2014/9/5
//  @ Author :
//
//

#include "../StdInc.h"

namespace GSTrader
{
	namespace TradeBase
	{
		CConnectionInfo::CConnectionInfo(int nType) : m_strInvestorID(""), m_strUserPassWord(""), m_strUserID(""), m_strProductInfo("")
		{
			m_pBroker = new CBroker;
			m_pBroker->m_nPlatformType = nType;
			m_nWaitMode = wmAsync;
			m_bReConn = false;
		}

		CConnectionInfo::~CConnectionInfo()
		{
			_delete(m_pBroker)
		}

		CConnectionInfo::CConnectionInfo(const CConnectionInfo& user)
		{
			(*this) = user;
		}

		bool CConnectionInfo::operator == (const CConnectionInfo& r)
		{
			return (m_strInvestorID == r.m_strInvestorID && m_strUserID == r.m_strUserID && ((*m_pBroker) == (*r.m_pBroker)));
		}

		CConnectionInfo& CConnectionInfo::operator = (const CConnectionInfo& r)
		{
			m_strInvestorID = r.m_strInvestorID;
			m_strUserPassWord = r.m_strUserPassWord;
			m_strUserID = r.m_strUserID;

			m_strQuotePassWord = r.m_strQuotePassWord;
			m_strProductInfo = r.m_strProductInfo;
			m_nWaitMode = r.m_nWaitMode;

			m_pBroker = new CBroker(*r.m_pBroker);
			return (*this);
		}

		void CConnectionInfo::Reset()
		{
			m_strInvestorID = "";
			m_strUserPassWord = "";
			m_strUserID = "";

			m_strQuotePassWord = "";
			m_strProductInfo = "";

			m_pBroker->Reset();
		}

		void CConnectionInfo::SetUser(string strInvestorID, string strUserPassWord, string strQuotePassWord)
		{
			m_strInvestorID = strInvestorID;
			m_strUserPassWord = strUserPassWord;
			m_strQuotePassWord = strQuotePassWord;
		}

		void CConnectionInfo::SetBrokerInfo(string strBrokerID, string strBrokerName)
		{
			m_pBroker->m_strBrokerID = strBrokerID;
			m_pBroker->m_strBrokerName = strBrokerName;
		}

		string CConnectionInfo::GetBrokerID()
		{
			return m_pBroker->m_strBrokerID;
		}

		void CConnectionInfo::AddTradeFront(string strUrl)
		{
			m_pBroker->AddTradeFront(strUrl);
		}

		void CConnectionInfo::AddQuoteFront(string strUrl)
		{
			m_pBroker->AddQuoteFront(strUrl);
		}

		void CConnectionInfo::SetPlatformType(int nPlatformType)
		{
			m_pBroker->m_nPlatformType = nPlatformType;
		}

		string CConnectionInfo::GetConnectionInfo()
		{
			if (m_pBroker == NULL)
				return "";

			string strInfo = m_pBroker->m_strBrokerName;
			strInfo += "(";
			strInfo += m_pBroker->m_strBrokerID;
			strInfo += ")";
			strInfo += "-";
			strInfo += m_strInvestorID;
			return strInfo;
		}

		int CConnectionInfo::GetAccountType()
		{
			int nType = m_pBroker->m_nPlatformType;
			if (nType == ptCTP || nType == ptFemas || nType == ptGfOms || nType == ptXgj)
				return atFuture;

			if (nType == ptLts || nType == ptCtpStock)
				return atStock;

			return atNone;
		}
	}
}